package com.hy.service.impl;

import com.hy.bean.Accusation;
import com.hy.dao.ReportDao;
import com.hy.service.ReportService;
import com.hy.utils.DateUtil;
import com.hy.utils.ResponseResult;
import com.hy.utils.ResultUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ReportServiceImpl implements ReportService {
    private ReportDao reportDao = new ReportDao();

    //查询所有举报
    public void listReport(HttpServletRequest request, HttpServletResponse response) throws Exception {

        List<Map<String, Object>> list = reportDao.selectReport();

        ResponseResult<List<Map<String, Object>>> result = new ResponseResult<>(200, "ok", list, 101);
        ResultUtils.result(result,request,response);
    }

    @Override
    public void addAccusation(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer cardId = Integer.valueOf(request.getParameter("cardId"));
        Integer reportId = Integer.valueOf(request.getParameter("reportId"));
        String content = request.getParameter("content");
        Integer createId = Integer.valueOf(request.getParameter("createId"));
        Integer commentId = Integer.valueOf(request.getParameter("commentId"));

        boolean flag = reportDao.insertAccusation(new Accusation(0,cardId,0,commentId,reportId,content, DateUtil.datetime(),null,createId,0,null,null));
        ResponseResult<?> result = new ResponseResult<>(200, "ok", flag, 101);
        ResultUtils.result(result,request,response);
    }
}
